﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>数据字典明细管理</title>
<#--要在script前引入-->
<#include "../common/link.ftl">
    <script>
        $(function () {
            $('.btn-input').click(function () {

                //清除模态框中表单里的旧有数据
                $('#editForm')[0].reset();
                //设置标题
                $('.modal-title').html('数据字典明细新增');
                $('select[name=parentId]').removeAttr("disabled")
                var data = $(this).data('json');
                var href = location.href;
                var arr = href.split("=");
                var num = arr[1];
                console.log(num);
                $('select[name=parentId]').val(num);
                //$('input[name=parentId]').val(num);
                //console.log(href);
                console.log(this);

                if (data) {
                    $('select[name=parentId]').prop("disabled",true)
                    $('.modal-title').html('数据字典明细编辑');
                    $('input[name=id]').val(data.id);
                    $('input[name=title]').val(data.title);
                    $('input[name=parentId]').val(data.parentId);
                    $('select[name=parentId]').val(data.parentId);
                    $('input[name=sequence]').val(data.sequence);
                }


                $('#editModal').modal('show');
            });


            $('.btn-submit').click(function () {
                $('#editForm').ajaxSubmit(function (data) {
                    if (data.success) {
                        $.messager.confirm("温馨提示", data.msg, function () {
                            window.location.reload();
                        });
                    } else {
                        $.messager.alert("温馨提示", data.msg);
                    }
                });
            });


        })
    </script>


</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
<#include "../common/navbar.ftl">
    <!--菜单回显-->
<#assign currentMenu = "systemDictionaryItem">
<#include "../common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>数据字典明细管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <div class="row box-body">
                    <div class="col-md-3">
                        <ul id="systemDictionaries" class="list-group">
                        <#list systemDictionaries as systemDictionary>
                            <li class="list-group-item ${(qo.parentId?? && qo.parentId ==  systemDictionary.id)?string('active', '')}"
                                name="systemDictionary"><a style="color: #333333"
                                                           href="/systemDictionaryItem/list?parentId=${systemDictionary.id}">${systemDictionary.title}</a>
                            </li>
                        </#list>
                        </ul>
                    </div>
                    <div class="col-md-9">
                        <!--高级查询--->
                        <form class="form-inline" id="searchForm" action="/systemDictionaryItem/list" method="post">
                            <input type="hidden" name="currentPage" id="currentPage" value="1">
                            <a class="btn btn-success btn-input" style="margin: 10px">
                                <span class="glyphicon glyphicon-plus"></span> 添加
                            </a>
                        </form>
                        <!--编写内容-->
                        <div class="box-body table-responsive no-padding ">
                            <table class="table table-hover table-bordered">
                                <tr>
                                    <th>编号</th>
                                    <th>标题</th>
                                    <th>目录</th>
                                    <th>顺序</th>
                                    <th>操作</th>
                                </tr>
                            <#list pageInfo.list as systemDictionaryItem>
                                <tr>
                                    <td>${systemDictionaryItem_index+1}</td>
                                    <td>${systemDictionaryItem.title}</td>
                                    <td>${systemDictionaryItem.parentId}</td>
                                    <td>${systemDictionaryItem.sequence}</td>
                                    <td>
                                        <a data-json='${systemDictionaryItem.jsonData}'
                                           class="btn btn-info btn-xs btn-input">
                                            <span class="glyphicon glyphicon-pencil"></span> 编辑
                                        </a>
                                        <@shiro.hasPermission name="systemDictionaryItem:delete">
                                            <a data-url="/systemDictionaryItem/delete?id=${systemDictionaryItem.id}"
                                               class="btn btn-danger btn-xs btn-delete">
                                                <span class="glyphicon glyphicon-trash"></span> 删除
                                            </a>
                                        </@shiro.hasPermission>
                                    </td>
                                </tr>
                            </#list>
                            </table>
                            <!--分页-->
                        <#include "../common/page.ftl">
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
<#include "../common/footer.ftl">
</div>
<!---数据字典明细编辑--->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">数据字典明细编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/systemDictionaryItem/saveOrUpdate" method="post" id="editForm">
                    <input type="hidden" name="id">
                    <#--因为disabled传值为空要用一个隐藏的parentId传值去封装-->

                    <div class="form-group">
                        <label class="col-sm-3 control-label">字典目录：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="parentId">
                            <#list systemDictionaries as systemDictionary>
                                <option value="${systemDictionary.id}">${systemDictionary.title}</option>
                            </#list>
                            </select>
                        </div>
                        <input type="hidden" name="parentId">
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">顺序：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="sequence">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn-submit">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
